package org.cfk.delaytasktutorial.example;

import cn.hutool.core.io.FileUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.cfk.delaytasktutorial.annotation.LazyJob;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FileCleanupTask {

    public static final String WORKER_NAME = "file_cleanup_task";

    @Data
    public static class FileCleanupParam {
        private String filePath;
    }

    @LazyJob(WORKER_NAME)
    public void cleanup(FileCleanupParam param) {
        log.info("开始执行文件清理任务，文件路径：{}", param.getFilePath());
        if (FileUtil.exist(param.getFilePath())) {
            FileUtil.del(param.getFilePath());
            log.info("文件清理成功：{}", param.getFilePath());
        } else {
            log.warn("文件不存在：{}", param.getFilePath());
        }
    }
}